package com.free.framework.settings;

import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceFragment;

import com.free.framework.R;
import com.free.framework.constants.Const;

/**
 * @author 李博
 * @date 2016年10月29日
 * @desc
 */
public class HostSettingFrag extends PreferenceFragment implements Preference.OnPreferenceChangeListener {


    private static final String[] HOST_KEYS = {Const.PerfKey.HOST_SERVER, Const.PerfKey.HOST_H5,
            Const.PerfKey.HOST_APPI};

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.preference);
        initSettings(HOST_KEYS);
    }

    @Override
    public boolean onPreferenceChange(Preference preference, Object newValue) {
        preference.setSummary(newValue.toString());
        return true;
    }

    private void initSettings(String[] keys) {
        ListPreference perfsHost = null;
        for (String key : keys) {
            perfsHost = (ListPreference) findPreference(key);
            if (null == perfsHost)
                return;
            perfsHost.setSummary(perfsHost.getValue());
            perfsHost.setOnPreferenceChangeListener(this);
        }
    }

}
